<?php
class Quantri_Model_Dmban extends Zend_Db_Table_Abstract
{
	protected $_name="dmban";
	protected $_primary="Id";

	var $Id, $Ten,$IdKhuVuc, $TrangThai, $DienGiai, $NgayTao;

	public function __construct() {
		$this->_name = Zend_Registry::get('tablePrefix') . $this->_name;

		parent::__construct();
	}


	public function GetAll() {

		$query = $this->_db->select()
	    						->from(array('T1'=>'os_dmban'))
	    						->joinLeft(array('T2' => 'os_khuvuc'), 'T1.IdKhuVuc = T2.Id', array('T2.Ten as KV'));								
	    
	    $stmt = $this->_db->query($query);
	    
	   return $result = $stmt->fetchAll();
	    
	    var_dump($result);
	}
	
	public function GetDmBanKhuVuc($IdKhuvuc) {
	
		$query = $this->_db->select()
		->from(array('T1'=>'os_dmban'))
		->joinLeft(array('T2' => 'os_khuvuc'), 'T1.IdKhuVuc = T2.Id', array('T2.Ten as KV'))
		->where ("T1.IdKhuVuc='". $IdKhuvuc . "'");
		$stmt = $this->_db->query($query);
		 
		return $result = $stmt->fetchAll();
		 
		var_dump($result);
	}

	public function save()
	{
		$data = array(
				//'Id' 	=> $this->Id,
				'Ten' => $this->Ten,
				'IdKhuVuc' => $this->IdKhuVuc,
				'TrangThai' => $this->TrangThai,
				'DienGiai' => $this->DienGiai,
				'NgayTao' => $this->NgayTao
		);
		if($this->Id == "-1")
			$this->insert($data);		
		else
			$this->update($data, "Id = '$this->Id'");
	}

	public function xoa($id)
	{
		$this->delete("id='". $id . "'");
	}
	public function GetById()
	{
		return $this->fetchAll("Id='$this->Id'", "", 1)->toArray();
	}
}